I have a table Answer in SQL Server like this:
QuestionID AnswerID AnswerContent IsTrue
1 1 1990 True
1 2 300$ False
1 3 1992 True
2 4 1993 False
2 5 400$ True
2 6 600$ False
5 7 Lion False
5 8 Tiger True
5 9 Elephant False
Because the AnswerID is an auto-increment and I don't know
exactly its value when running the query.
So how can I update the AnswerContent column?
Example: I need to update
"Tiger - False" to "Elephant - True"
"Lion - True" to "1992 - False"
--- Update ---
I cannot change the table structure because it's my
teacher's order.
Aryan Kumar
28-Apr-2023To update multiple cells in one column with the same ID in SQL, you can use the UPDATE statement with a WHERE clause to specify the condition for the rows to be updated.
Here's an example of how to update multiple cells in a column with the same ID:
In this example, table_name is the name of the table, column_name is the name of the column that you want to update, new_value is the value that you want to update the cells to, id is the name of the column that contains the ID values, and your_id is the ID value that you want to update.
For instance, let's say you have a table named customers with columns id, name, and email. If you want to update the email of all customers with the ID 5 to "new_email@example.com", you can use the following SQL statement:
This will update all rows in the customers table with the ID 5 and set their email to "new_email@example.com".
Anchal Kesharwani
22-Sep-2014hi pravesh,
you need to try this:
You can do it in one shot using the CASE expression. Here is an example: